package me.zhengjie.modules.inspection.repository;

import me.zhengjie.modules.inspection.domain.TInspectionTask;

import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
* @author xuyukun
* @date 2019-07-21
*/
public interface TInspectionTaskRepository extends JpaRepository<TInspectionTask, Long>, JpaSpecificationExecutor {

	@Query(value="SELECT * from t_inspection_task where NOT EXISTS (SELECT 1 from t_work_order where t_inspection_task.id=t_work_order.source_id)",nativeQuery = true)
	public List<TInspectionTask> findInspectionTaskWithOrder();

	@Query(nativeQuery = true, value="select a.*,b.id as task_id, b.operate_time,b.state as state2 from inspection_plan a, t_inspection_task b where a.id=b.plan_id ",
	countQuery = "select count(1) from inspection_plan a, t_inspection_task b where a.id=b.plan_i")
	Page<Map<String,Object>> queryInspectionTask(Pageable pageable);
}